package com.atde._03_creational_design_patterns.fcatory.factorymethod.pizzastore.order;

import com.atde._03_creational_design_patterns.fcatory.factorymethod.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @BelongsProject: hsp_java_design_mode
 * @BelongsPackage: com.atde._03_creational_design_patterns.fcatory.factorymethod.pizzastore.order
 * @Author: Del
 * @CreateTime: 2025-06-03  00:26
 * @Description: 工厂方法 --  订购披萨抽象类
 * @Version: 1.0
 */
public abstract class OrderPizza {

    public OrderPizza () {
        Pizza  pizza = null;
        String orderType;
        do {
            // 订购披萨的类型
            orderType = createPizzas();
            // 抽象方法，实际由工厂子类实现
            pizza = createPizza(orderType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
                 System.out.println("披萨订购完毕");
            }  else {
                System.out.println("订购披萨失败");
                break;
            }
        }  while (true);
    }

    // 定义一个抽象方法， createPizza 方法，让各个工厂子类自己实现
    abstract Pizza createPizza(String orderType);

    /***
     * @author: Del
     * @date: 2025/6/2 23:15
     * @return String 披萨的类型
     * @description:  用于获取订购披萨的类型
     */
    private String createPizzas() {
        try {
            BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("请输入披萨类型：");
            return buf.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
